package main

import (
	"fmt"
)

func div(a, b int) (int, error) {
	if b == 0 {
		err := New("除以0错误")
		return 0, err
	} else {
		return a / b, nil
	}

}

type errorString struct {
	s string
}

func New(t string) error {
	return &errorString{t}

}
func (e *errorString) Error() string {
	return e.s
}

type MyInt int

func New2(i MyInt) error {
	return &i
}

func (i *MyInt) Error() string {
	return fmt.Sprintf("我是int%d 的扩展\n", *i)
}

func main() {

	if r, err := div(5, 0); err != nil {
		fmt.Println("有错误", err.Error())
		fmt.Println("有错误", err)
	} else {
		fmt.Println("没有错误", r)

	}

	//fmt.Println(div(5, 0))
	//var i MyInt = 3
	//fmt.Println(New2(i))
}
